package com.colin.app.activity.splash;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.widget.TextView;

import com.colin.app.R;
import com.colin.app.app.AppActivity;
import com.colin.library.help.LogHelp;
import com.colin.library.help.permission.PermissionHelp;

import java.util.List;

public class SplashActivity extends AppActivity implements SplashContract.SplashView {
    private SplashContract.SplashPresenter mSplashPresenter = null;
    private TextView text_splash_welcome;

    @Override
    protected void onDestroy() {
        mSplashPresenter.destroy();
        mSplashPresenter = null;
        super.onDestroy();
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        super.onCreate(savedInstanceState);
    }

    @Override
    public void initPresenter() {
        mSplashPresenter = new SplashPresenterImpl(this, this);
    }

    @Override
    public int initViewLayoutID() {
        return R.layout.activity_splash;
    }

    @Override
    public void initView() {
        this.text_splash_welcome = (TextView) this.findViewById(R.id.text_splash_welcome);
    }

    @Override
    public void initData() {
        mSplashPresenter.setData();
    }


    @Override
    public boolean initPermissionList(List<String> permissionList) {
        return PermissionHelp.getInstance().checkPermission(this, permissionList);
    }

    @Override
    public void startAnimation(Animation animation) {
        this.text_splash_welcome.setVisibility(View.VISIBLE);
        this.text_splash_welcome.setAnimation(animation);
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        LogHelp.e("requestCode==" + String.valueOf(requestCode));
        if (grantResults.length < 1) {
            LogHelp.e("权限请求失败");
        }
        for (String permission : permissions) {
            LogHelp.e("权限请求=permissions=" + permission);
        }
        for (int result : grantResults) {
            LogHelp.e("权限请求=result=" + String.valueOf(result));
        }

        if (requestCode == PermissionHelp.REQUEST_CODE_MORE) {
            mSplashPresenter.next();
        }

        if (PermissionHelp.getInstance().onRequestPermissionsResult(grantResults)) {

        } else {
            super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        }
    }
}
